const checkData=require("../utils/checkData")
const {successModel,notFoundModel,errorModel,lackModel}=require("../utils/resModel")
const {addInfo,getInfo}=require("../controller/timeController");
const {getUserInfo} = require("../controller/userController");
const timeRouter = async (req, res) => {
     /**
     * 
     * @api {POST} api/time/addInfo 新增时间
     * @apiName 新增时间
     * @apiGroup Time
     * @apiVersion  1.0.0
     * 
     * 
     * @apiParam  {String} date 场次时间
     * 
     * 
     * @apiParamExample  {type} Request-Example:
     * {
     *      date : "2020-11-29"
     * }
     * 
     * 
     * @apiSuccessExample {type} Success-Response:
     * {
     *     {
     *          msg: "成功添加场次时间"
     *     }
     * }
     * 
     * 
     */
    if (req.method === "POST" && req.path === "/api/time/addInfo") {
        let checkRes=checkData(req,"date");
        if(typeof checkRes==="boolean"){
            let timeRes=await addInfo(req.body);
            // 数据存放的地方
                if(timeRes.affectedRows){
                    return successModel("成功添加场次时间")
                }else{
                    return errorModel(timeRes.message);
                }
        }else{
            return lackModel(`${checkRes}参数不正确`)
        }
    }

  /**
     * 获取时间功能
     */
    /**
     * 
     * @api {GET} api/time/getInfo 获取时间
     * @apiName 获取时间
     * @apiGroup Time
     * @apiVersion  1.0.0
     * 
     * 
     * 
     * @apiParamExample  {type} Request-Example:
     * {
     *      
     * }
     * 
     * 
     * @apiSuccessExample {type} Success-Response:
     * {
     *      {
                "id": 8,
                "time": "1606348800000"
            }
     * }
     * 
     * 
     */
    if (req.method === "GET" && req.path === "/api/time/getInfo") {
        let timeRes =await getInfo();
        if(timeRes.length){
            return successModel(timeRes);
        }else{
            return errorModel("缺少场次日期数据！！！");
        }
    }
}
module.exports = timeRouter;